#pragma once

#include "../Datasources/WavFileSampleReader.h"
#include "../Datasources/FolderReader.h"
#include "../Classifiers/KNN.h"
#include "../Classifiers/ChaineApprentissage.h"
#include "../FeatureProcessing/Preaccentuation.h"
#include "../FeatureProcessing/Normalisation.h"
#include "../FeatureProcessing/Labelisation.h"
#include "../FeatureProcessing/MFCC.h"
#include "../FeatureProcessing/DistanceFrameDeletion.h"
#include "../FeatureProcessing/Concatenate.h"
#include "../FeatureProcessing/ClassifierNumericAdapter.h"
#include "../Entities/Array.h"
#include "../Utilities/MatlabProcess.h"
#include "../Utilities/TagRule.h"
#include "../Outputs/ResultConsoleWriter.h"
#include "../Outputs/ResultFileWriter.h"
#include "../Outputs/TextFormatting.h"
#include "../Outputs/TextFormatting.h"
#include "ProgressRecognition.h"

using namespace DataSources;
using namespace Classifiers;
using namespace FeatureProcessing;
using namespace Entities;
using namespace Utilities;
using namespace Outputs;

class ChaineKNN : public ChaineApprentissage {
protected :
	WavFileSampleReader::type_pointer wavFile;

public:
	ChaineKNN(string _baseA, 
			string _baseT, 
			string _dest, 
			Array<TagRule> & _rules,
			bool _resize = true, 
			bool _normalize = false, 
			int _nbVoisins = 3, 
			int _nbCoeffs = 3, 
			int _nbSamplesPerFrame = 260, 
			int _nbFiltres = 10, 
			int _nbFrames = 25):
		ChaineApprentissage(new KNN(_nbVoisins)){

		wavFile = new WavFileSampleReader;
		setTrainingReader(new FolderReader(wavFile, _baseA));
		setReader(new FolderReader(wavFile, _baseT));
		addProcessor(new Filtres::Preaccentuation);
		if (_normalize) addProcessor(new Normalisation);
		addProcessor(new Labelisation(_rules));
		//addProcessors(new Adapters::ClassifierNumericAdapter(_clustering));
		addProcessor(new MFCC(_nbCoeffs, _nbSamplesPerFrame, _nbFiltres));
		if (_resize) addProcessor(new Redimensionnement::DistanceFrameDeletion(_nbFrames));
		addProcessor(new Concatenate);
		ResultFormattingPtr formatting = new TextFormatting();
		addListener(new ProgressRecognition(reader->getLen()));
		setWriter(new ResultFileWriter(formatting, _dest));
	}

	void train(){
		ChaineApprentissage::train();
	}

	void recognize(){
		ChaineApprentissage::recognize();
	}
};
